Skip to content

fix: replace vite env variables in source attr#15

Open
csbun wants to merge 2 commits into
donnikitos:masterfrom
csbun:master
Open

fix: replace vite env variables in source attr#15
csbun wants to merge 2 commits into
donnikitos:masterfrom
csbun:master

Conversation

@csbun
Copy link
Copy Markdown

@csbun csbun commented Mar 4, 2025

As we are running this plugin in order: 'pre', so %VITE_ENV_VARIABLES% will not replace when function renderSnippets runs. In this case, we need to replace it manually. For example:

<load src="path/to/%MODE%/file.html" />

will be threaded as:

<load src="path/to/development/file.html" />

@donnikitos
Copy link
Copy Markdown
Owner

That's actually a pretty valid point and a good addition!
Although I would prefer to have the same implementation as in Vite itself. You can use this piece of code: https://github.com/donnikitos/vite-plugin-php/blob/master/src/utils/replaceEnv.ts it is extracted from Vite and should be easily implemented.

If you don't wanna bother, I can take over your PR and add it.

@csbun
Copy link
Copy Markdown
Author

csbun commented Mar 6, 2025

Taken the latest htmlEnvHook from vite/src/node/plugins/html.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants